<!--
tabs-item: lab: tab显示字段; badge: 标记
-->
<template>
  <ul :class="[!isNewTabs ? 'custom-tabs-box' : 'new-tabs-wrap']">
    <el-badge
      v-for="(item, index) in tabsArr"
      :key="index"
      :hidden="isHiddenZero && !item.badge.value"
      :max="maxNum"
      v-bind="item.badge"
    >
      <li class="tabs-item" :class="{ active: index === tabsActiveIndex }" @click.stop="tabsHandle(index)">
        <span class="item-font" :class="{ 'dis-btn': item.disabled }">{{ item.lab }}</span>
        <span class="item-border" />
      </li>
    </el-badge>
  </ul>
</template>
<script>
export default {
  name: 'CustomTabs',
  props: {
    isNewTabs: {
      type: Boolean,
      default: false
    },
    isHiddenZero: {
      type: Boolean,
      default: false
    },
    activeIndex: {
      type: Number,
      default: 0
    },
    maxNum: {
      type: Number,
      default: 99
    },
    tabsArr: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      tabsActiveIndex: null
    };
  },
  data() {
    return {
      tabsActiveIndex: null
    };
  },
  data() {
    return {
      tabsActiveIndex: null,
      max: 99
    };
  },
  watch: {
    activeIndex: {
      immediate: true,
      handler(val) {
        this.tabsActiveIndex = val;
      }
    }
  },
  watch: {
    activeIndex: {
      immediate: true,
      handler(val) {
        this.tabsActiveIndex = val;
      }
    }
  },
  watch: {
    activeIndex: {
      immediate: true,
      handler(val) {
        this.tabsActiveIndex = val;
      }
    }
  },
  methods: {
    tabsHandle(index) {
      if (this.tabsArr[index].disabled) {
        return;
      }
      this.tabsActiveIndex = index;
      this.$emit('returnIndex', index);
    }
  }
};
</script>
<style lang="less" scope>
@import '../../assets/var.less';

.custom-tabs-box {
  padding-left: 0;
  height: 45px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin-bottom: 10px;

  .tabs-item {
    list-style: none;
    padding: 0 20px;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    cursor: pointer;

    .item-font {
      display: flex;
      align-items: center;
      height: 100%;
      font-size: 14px;
      font-weight: bold;
      color: @weakFontColor;
    }

    .item-border {
      display: inline-block;
      height: 2px;
      width: 20px;
      border-radius: 2px;
      background-color: transparent;
    }

    &.active {
      font-size: 20px;
      font-weight: bold;
      line-height: 28px;

      .item-font {
        font-size: 20px;
        color: @themeBlue;
      }

      .item-border {
        background-color: @themeBlue;
      }
    }
  }
  .dis-btn {
    // eslint-disable-next-line no-tabs
    color: #c2c2c2 !important;
  }
  .el-badge__content.is-fixed {
    right: 25px;
  }
}
.new-tabs-wrap {
  padding-left: 0;
  height: 57px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  background: #fff;
  margin-bottom: 8px;
  .el-badge {
    height: 100%;
    .el-badge__content.is-fixed {
      top: 15px;
    }
  }
  .tabs-item {
    position: relative;
    list-style: none;
    padding: 0 16px 0 8px;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    cursor: pointer;
    .item-font {
      display: flex;
      align-items: center;
      height: 100%;
      font-size: 14px;
      color: @weakFontColor;
    }

    .item-border {
      display: inline-block;
      height: 2px;
      border-radius: 2px;
      background-color: transparent;
    }

    &.active {
      height: 100%;

      .item-font {
        font-size: 20px;
        color: @themeBlue;
      }

      .item-border {
        width: 100%;
        background-color: @themeBlue;
      }
    }
  }
  .dis-btn {
    // eslint-disable-next-line no-tabs
    color: #c2c2c2 !important;
  }
  .el-badge__content.is-fixed {
    right: 25px;
  }
}
</style>
